﻿CREATE PROCEDURE [dbo].[sp_Get_Order]
	@AccountID VARCHAR(10),
	@Month int,
	@Year int
AS
	SET NOCOUNT ON
	SELECT o.*, 
	(select MAX(zi.ZipID) 
	from OrderZip oz, ZipInfo zi 
	where OrderID = o.OrderID 
	and oz.ZipID = zi.ZipID
	and (zi.AgentName is null
	or zi.AgentName = '')) IsAssigned
	FROM dbo.Orders o
	WHERE o.AccountID=@AccountID 
	and o.PeroidMonth = @Month 
	and o.PeroidYear = @Year